package com.vhuan.self_discipline_service.controller.battery;

import cn.hutool.core.bean.BeanUtil;
import com.vhuan.self_discipline_service.domain.battery.dto.BatteryBehaviorDTO;
import com.vhuan.self_discipline_service.domain.battery.dto.BatteryDTO;
import com.vhuan.self_discipline_service.domain.battery.vo.BatteryVO;
import com.vhuan.self_discipline_service.service.battery.BatteryService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.Collections;
import java.util.List;
import java.util.Map;

@Tag(name = "电池管理服务")
@RestController
@RequestMapping("/battery")
@RequiredArgsConstructor
public class BatteryController {

    private final BatteryService batteryService;
    @Operation(summary = "获取电池列表", description = "获取电池列表")
    @GetMapping("/{uid}")
    public Map<String, List<BatteryVO>> getBatteryList(@Parameter(description = "用户ID") @PathVariable("uid") Long uid) {
        List<BatteryDTO> list=batteryService.getBatteryList(uid);

        return Collections.singletonMap("list", BeanUtil.copyToList(list, BatteryVO.class));
    }

    @Operation(summary = "添加电池", description = "添加电池")
    @PostMapping
    public void addBattery(@Parameter(description = "电池信息") @RequestBody BatteryDTO batteryDTO){
        batteryService.addBattery(batteryDTO);
    }

    @Operation(summary = "删除电池", description = "删除电池")
    @DeleteMapping("/{uid}/{battery_id}")
    public void deleteBattery(@Parameter(description = "电池ID") @PathVariable("battery_id") Long battery_id){
        batteryService.deleteBattery(battery_id);
    }

    @Operation(summary = "添加电池行为", description = "添加电池行为")
    @PostMapping("/{uid}/{battery_id}/behavior")
    public void addBatteryBehavior(@Parameter(description = "电池行为信息") @RequestBody BatteryBehaviorDTO batteryBehaviorDTO){
        batteryService.addBatteryBehavior(batteryBehaviorDTO);
    }

    @Operation(summary = "删除电池行为", description = "删除电池行为")
    @DeleteMapping("/{uid}/{battery_id}/behavior/{battery_behavior_id}")
    public void deleteBatteryBehavior(Long battery_behavior_id){
        batteryService.deleteBatteryBehavior(battery_behavior_id);
    }
}
